package com.hzlx.dao.impl;

import com.hzlx.dao.BaseDao;
import com.hzlx.dao.TOrderInfoDao;
import com.hzlx.entity.TFoodInfo;
import com.hzlx.entity.TOrderInfo;

import java.util.Date;
import java.util.List;

/**
 * @author 86166
 * @version 1.0
 * @description: TODO
 * @date 2023/4/9 22:36
 */
public class TOrderInfoDaoImpl extends BaseDao<TOrderInfo> implements TOrderInfoDao {
    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete * from t_order_info where id=?";
        return executeUpdate(sql, id);
    }

    @Override
    public int insert(TOrderInfo record) {
        String sql = "insert into t_order_detail_info values(?,?,?,?,?,?,?,default)";
        return executeUpdate(sql,null,record.getUserId(),record.getBusinessId(),record.getDesc(),record.getTotalMoney(),new Date());
    }

    @Override
    public int insertSelective(TOrderInfo record) {
        return 0;
    }

    @Override
    public TOrderInfo selectByPrimaryKey(Integer id) {
        String sql = "select * from t_order_info where id = ?";
        List<TOrderInfo> tOrderInfos = executeQuery(sql, TFoodInfo.class, id);
        TOrderInfo tOrderInfo = null;
        if (tOrderInfos.size()>0) {
            for (TOrderInfo orderInfo : tOrderInfos) {
                tOrderInfo = orderInfo;
            }
        }
        return tOrderInfo;
    }

    @Override
    public int updateByPrimaryKeySelective(TOrderInfo record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(TOrderInfo record) {
        String sql = "update t_order_info set order_no=?,user_id=?, desc=?,total_money=?,create_time=?,status=? where id=?";
        return executeUpdate(sql,record.getOrderNo(),record.getUserId(),record.getTotalMoney(),record.getCreateTime(),record.getStatus(),record.getId());
    }

    @Override
    public List<TOrderInfo> selectPendingOrderList(Integer businessId) {
        String sql = "select * from t_order_info where business_id=? and `status`=3";
        return executeQuery(sql, TOrderInfo.class, businessId);

    }

    @Override
    public int updateOrderStatus(String orderId) {
        String sql = "update t_order_info set `status`=2 where order_no=?";
        return executeUpdate(sql, orderId);
    }

    @Override
    public List<TOrderInfo> selectOrderListAll(Integer businessId) {
        String sql = "select * from t_order_info where business_id=?";
        return executeQuery(sql, TOrderInfo.class, businessId);
    }
}
